package LeetCode;

public class LC_434_NumberofSegmentsinaString {

    public static void main(String[] args) {

    }

    static class Solution {
        public int countSegments(String s) {
            int res = 0;
            for (int i = 0; i < s.length(); i++)
                if (s.charAt(i) != ' ' && (i == 0 || s.charAt(i - 1) == ' '))
                    res++;
            return res;
        }

    }
}